const Koa = require('koa')
const json = require('koa-json')
const logger = require('koa-logger')
const serve = require('koa-static')
const views = require('koa-views')
const koaBody = require('koa-body')
const path = require('path') // 导入path包 用于拼接路径
const router = require('./router')
require('./models')

const app = new Koa()
app.use(json())
app.use(logger())
app.use(
  koaBody({
    multipart: true,
    formidable: {
      maxFileSize: 200 * 1024 * 1024 // 设置上传文件大小最大限制，默认2M
    }
  })
)

app.use(serve(path.join(__dirname, 'static')))

app.use(views(path.join(__dirname, 'views'), { map: { html: 'ejs' } }))

app.use(router.routes(), router.allowedMethods())

app.listen(8000, () => {
  console.log('server is running at http://localhost:8000')
})
